import java.util.Scanner;

/**
 * Created by 14229 on 2020/2/27.
 */
public class Test04_05 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入年份：");
        int nian = sc.nextInt();
        System.out.println("请输入月份：");
        int yue = sc.nextInt();
        if (nian%400==0 || nian%4==0 && nian%100!=0){
            if (yue==2){
                for (int i = 1; i <=29 ; i++) {
                    if (i%7==0){
                        System.out.print(i);
                        System.out.println();
                    }else {
                        System.out.print(i+" ");
                    }
                }
            }
            getyue(yue);
        }else {
            if (yue==2){
                for (int i = 1; i <=28 ; i++) {
                    if (i%7==0){
                        System.out.print(i);
                        System.out.println();
                    }else {
                        System.out.print(i+" ");
                    }
                }
            }
            getyue(yue);
        }
    }
    public static void getyue(int yue){
        switch (yue){
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                for (int i = 1; i <=31 ; i++) {
                    if (i%7==0){
                        System.out.print(i);
                        System.out.println();
                    }else {
                        System.out.print(i+" ");
                    }
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                for (int i = 1; i <=30 ; i++) {
                    if (i%7==0){
                        System.out.print(i);
                        System.out.println();
                    }else {
                        System.out.print(i+" ");
                    }
                }
                break;
        }
    }
}
